// 加载配送员数据
async function loadDeliveryPersonsData() {
    try {
        const response = await fetch(`${API_BASE_URL}/delivery-persons`, {
            method: 'GET',
            credentials: 'same-origin'
        });
        
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        
        const deliveryPersons = await response.json();
        displayAllDeliveryPersons(deliveryPersons);
    } catch (error) {
        console.error('加载配送员数据失败:', error);
        showAlert('加载配送员数据失败，请刷新页面重试。', 'danger');
    }
}

// 显示所有配送员数据
function displayAllDeliveryPersons(deliveryPersons) {
    if (!deliveryPersons || deliveryPersons.length === 0) {
        deliveryPersonsFullTable.innerHTML = '<tr><td colspan="5" class="text-center">暂无配送员数据</td></tr>';
        return;
    }
    
    const deliveryPersonsHtml = deliveryPersons.map(person => `
        <tr>
            <td>${person.id}</td>
            <td>${person.name}</td>
            <td>${person.phone}</td>
            <td><span class="badge ${getDeliveryPersonStatusBadgeClass(person.status)}">${formatDeliveryPersonStatus(person.status)}</span></td>
            <td>
                <button class="btn btn-sm btn-outline-primary" onclick="viewDeliveryPersonDetail('${person.id}')">查看</button>
            </td>
        </tr>
    `).join('');
    
    deliveryPersonsFullTable.innerHTML = deliveryPersonsHtml;
}

// 导出函数
window.loadDeliveryPersonsData = loadDeliveryPersonsData;